package com.ds.infrastructure.hyperspace.console.dto.apirouter;

import com.ds.infrastructure.hyperspace.console.dto.configdata.NodesDTO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author: yaozhendong
 * @create: 2019-12-11 10:21
 **/
@Data
@NoArgsConstructor
public class ApiRouterTargetProtocolConfig implements Serializable {
    private Integer weight;
    private Integer connectionMaxPoolSize;
    private Boolean overrideHostHeader;
    private String customHostHeader;

    public static ApiRouterTargetProtocolConfig toApiRouter(NodesDTO dto) {
        if (dto == null) {
            return null;
        }
        if (dto.getWeight() == null &&
                dto.getConnectionMaxPoolSize() == null &&
                dto.getOverrideHostHeader() == null &&
                dto.getCustomHostHeader() == null) {
            return null;
        }
        ApiRouterTargetProtocolConfig apiRouterTargetProtocolConfig = new ApiRouterTargetProtocolConfig();
        apiRouterTargetProtocolConfig.setWeight(dto.getWeight());
        apiRouterTargetProtocolConfig.setConnectionMaxPoolSize(dto.getConnectionMaxPoolSize());
        apiRouterTargetProtocolConfig.setOverrideHostHeader(dto.getOverrideHostHeader());
        apiRouterTargetProtocolConfig.setCustomHostHeader(dto.getCustomHostHeader());
        return apiRouterTargetProtocolConfig;
    }
}
